﻿using System;
using ITSP.SharePoint.CacheRefresh.Examples.Configuration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;

namespace ITSP.SharePoint.CacheRefresh.Examples.Layouts.ITSP.SharePoint.CacheRefresh.Examples
{
    /// <summary>
    /// Results Page to show the Example Configuration
    /// </summary>
    public partial class Results : LayoutsPageBase
    {
        /// <summary>
        /// Executed when the Results Page Loads
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Executed when the Page OnLoad event is fired.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            
            //load in the configuration values.
            ExampleConfigurationManager manager = ExampleConfigurationManager.Current;
            ExampleConfiguration configuration = manager.Configuration;
            
            if(configuration!=null)
            {
                lblConfigurationName.Text = configuration.ExampleConfigurationName;
                lblConfigurationValue.Text = configuration.ExampleConfigurationValue.ToString();
                lblConfigurationStartDate.Text = configuration.ExampleConfigurationStartDate.ToString();
                lblConfigurationCreated.Text = configuration.Created.ToString();
                lblConfigurationModified.Text = configuration.Modified.ToString();
            }
        }

        /// <summary>
        /// Closes the page when the Ok button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnButtonOk_Click(object sender, EventArgs e)
        {
            string webHomeUrl = SPContext.Current.Web.Url;
            SPUtility.Redirect(webHomeUrl, SPRedirectFlags.Default, System.Web.HttpContext.Current);
        }
    }
}
